﻿using System.Windows.Forms;

namespace Storm.TextEditor.Interacting.Keyboard
{
    /// <summary>
    /// Used when the user does a KeyboardAction.
    /// </summary>
    public delegate void ActionDelegate();

    /// <summary>
    /// Represents a relation between pressed keys and a delegate.
    /// </summary>
    public class KeyboardAction
    {
        #region Members

        private bool shift = false;
        private bool alt = false;
        private bool control = false;
        private bool allowReadOnly = false;

        private Keys key = 0;
        private ActionDelegate action = null;

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets whether the KeyboardAction requires the Shift key to be pressed.
        /// </summary>
        public bool Shift
        {
            get { return shift; }
            set { shift = value; }
        }

        /// <summary>
        /// Gets or sets whether the KeyboardAction requires the Alt key to be pressed.
        /// </summary>
        public bool Alt
        {
            get { return alt; }
            set { alt = value; }
        }

        /// <summary>
        /// Gets or sets whether the KeyboardAction requires the Control key to be pressed.
        /// </summary>
        public bool Control
        {
            get { return control; }
            set { control = value; }
        }

        /// <summary>
        /// Gets or sets whether the delegate that has been set for the KeyboardAction may be run when the parent TextEditor is readonly.
        /// </summary>
        public bool AllowReadOnly
        {
            get { return allowReadOnly; }
            set { allowReadOnly = value; }
        }

        /// <summary>
        /// Gets or sets the key that the KeyboardAction should register.
        /// </summary>
        public Keys Key
        {
            get { return key; }
            set { key = value; }
        }

        /// <summary>
        /// Gets or sets the delegate that the KeyboardAction should run.
        /// </summary>
        public ActionDelegate Action
        {
            get { return action; }
            set { action = value; }
        }

        #endregion

        /// <summary>
        /// Initializes the KeyboardAction.
        /// </summary>
        /// <param name="key">The key that should trigger the Action.</param>
        /// <param name="shift">Whether Shift needs to be down when the user presses the key to run the Action.</param>
        /// <param name="control">Whether Control needs to be down when the user presses the key to run the Action.</param>
        /// <param name="alt">Whether Alt needs to be down when the user presses the key to run the Action.</param>
        /// <param name="allowreadonly">Whether the Action should be able to be performed when the TextEditor is readonly.</param>
        /// <param name="actionDelegate">What delegate to use for the Action.</param>
        public KeyboardAction(Keys key, bool shift, bool control, bool alt, bool allowreadonly, ActionDelegate actionDelegate)
        {
            this.Key = key;
            this.Control = control;
            this.Alt = alt;
            this.Shift = shift;
            this.Action = actionDelegate;
            this.AllowReadOnly = allowreadonly;
        }
    }
}
